<%--
  Created by IntelliJ IDEA.
  User: XTT
  Date: 2022/10/9
  Time: 19:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>新增用户</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/lib/layui-v2.6.3/css/layui.css" media="all">
    <style>
        #layui-layer1 {
            width: 819px !important;
        }

        .layui-layer-content {
            height: auto;
        }

        .layui-form {
            width: 80%;
            padding-top: 30px;
        }
        p{
            color: red;
        }
    </style>
</head>
<body>
    <form id="form-add" class="layui-form" action="/client/add" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label">手机号码</label>
            <div class="layui-input-block">
                <input type="text" name="phone" required  lay-verify="required|phone" placeholder="请输入手机号码" autocomplete="off" class="layui-input">
                <p id="a"></p>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">身份证</label>
            <div class="layui-input-block">
                <input type="text" name="idCard" required  lay-verify="required|idCard" placeholder="请输入身份证" autocomplete="off" class="layui-input">
                <p id="b"></p>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户姓名</label>
            <div class="layui-input-block">
                <input type="text" name="clientName" required  lay-verify="required|clientName" placeholder="请输入姓名" autocomplete="off" class="layui-input">

            </div>
        </div>
<%--        <div class="layui-form-item">--%>
<%--            <label class="layui-form-label">选择框</label>--%>
<%--            <div class="layui-input-block">--%>
<%--                <select name="city" lay-verify="required">--%>
<%--                    <option value=""></option>--%>
<%--                    <option value="0">北京</option>--%>
<%--                    <option value="1">上海</option>--%>
<%--                    <option value="2">广州</option>--%>
<%--                    <option value="3">深圳</option>--%>
<%--                    <option value="4">杭州</option>--%>
<%--                </select>--%>
<%--            </div>--%>
<%--        </div>--%>
<%--        <div class="layui-form-item">--%>
<%--            <label class="layui-form-label">复选框</label>--%>
<%--            <div class="layui-input-block">--%>
<%--                <input type="checkbox" name="like[write]" title="写作">--%>
<%--                <input type="checkbox" name="like[read]" title="阅读" checked>--%>
<%--                <input type="checkbox" name="like[dai]" title="发呆">--%>
<%--            </div>--%>
<%--        </div>--%>
<%--        <div class="layui-form-item">--%>
<%--            <label class="layui-form-label">开关</label>--%>
<%--            <div class="layui-input-block">--%>
<%--                <input type="checkbox" name="switch" lay-skin="switch">--%>
<%--            </div>--%>
<%--        </div>--%>

<%--        <div class="layui-form-item layui-form-text">--%>
<%--            <label class="layui-form-label">文本域</label>--%>
<%--            <div class="layui-input-block">--%>
<%--                <textarea name="desc" placeholder="请输入内容" class="layui-textarea"></textarea>--%>
<%--            </div>--%>
<%--        </div>--%>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</body>
<script src="${pageContext.request.contextPath}/static/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath}/static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath}/static/lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>
<script>

    layui.use('form', function(){
        var form = layui.form;
        var $=layui.$;

        form.verify({
            pass: [
                /^[\S]{6,20}$/
                , '密码必须6到20位，且不能出现空格'
            ]
            , phone: function (value) {
                if (value.length != 11) {
                    return '新手机号必须为11位合法数字';
                }
                var reg = /^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/;
                if (reg.test(value)) {
                    // return '手机号码格式正确';
                } else {
                    return '非法手机号';
                }
            }
            , idCard: function (value) {
                if (value.length != 18) {
                    return '身份证号必须为18位合法数字';
                }
                var reg = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
                if (reg.test(value)) {
                    // return '身份证号格式正确';
                } else {
                    return '非法身份证号';
                }
            }, clientName: function (value) {
                var reg = /^[\u4e00-\u9fa5]{2,4}$/;
                if (reg.test(value)) {
                    // return '身份证号格式正确';
                } else {
                    return '请输入正确的姓名格式';
                }
            }
        })

        //监听提交
        form.on('submit(formDemo)', function(data){

            //发起异步提交
            let  url ='${pageContext.request.contextPath}/client/add'
            $.post(url,data.field,function (response) {
                if (response.code==0){
                    //成功的提示
                    layer.msg('',{
                        icon:1,
                        time:500 //2秒关闭 （如果不配置，默认是3秒）
                    },function () {
                        //关闭当前窗口
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                        //刷新表格
                        parent.reflushTable()
                    })
                }else {
                    //错误的提示
                    alert("失败")
                }
            })

            return false;
        });
    });
</script>
</html>
